Telegram Group & Telegram Channel
18. Program to Find GCDLCM.

import java.util.Scanner;

class GCDLCM
{
public static void main(String args[])
{
int x, y;
Scanner sc = new Scanner(System.in);

System.out.println("Enter the two numbers: ");
x = sc.nextInt();
y = sc.nextInt();

System.out.println("GCD of two numbers is : " + gcd(x, y));
System.out.println("LCM of two numbers is : " + lcm(x, y));
}

static int gcd(int x, int y)
{
int r = 0, a, b;
a = (x > y) ? x : y; // a is greater number
b = (x < y) ? x : y; // b is smaller number

r = b;
while (a % b != 0)
{
r = a % b;
a = b;
b = r;
}
return r;
}

static int lcm(int x, int y)
{
int a;
a = (x > y) ? x : y; // a is greater number
while (true)
{
if (a % x == 0 && a % y == 0)
{
return a;
}
++a;
}
}
}

@java_codings



tg-me.com/java_codings/27
Create:
Last Update:

18. Program to Find GCDLCM.

import java.util.Scanner;

class GCDLCM
{
public static void main(String args[])
{
int x, y;
Scanner sc = new Scanner(System.in);

System.out.println("Enter the two numbers: ");
x = sc.nextInt();
y = sc.nextInt();

System.out.println("GCD of two numbers is : " + gcd(x, y));
System.out.println("LCM of two numbers is : " + lcm(x, y));
}

static int gcd(int x, int y)
{
int r = 0, a, b;
a = (x > y) ? x : y; // a is greater number
b = (x < y) ? x : y; // b is smaller number

r = b;
while (a % b != 0)
{
r = a % b;
a = b;
b = r;
}
return r;
}

static int lcm(int x, int y)
{
int a;
a = (x > y) ? x : y; // a is greater number
while (true)
{
if (a % x == 0 && a % y == 0)
{
return a;
}
++a;
}
}
}

@java_codings

BY Advance Java πŸ‘¨β€πŸ’»


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/java_codings/27

View MORE
Open in Telegram


Advance Java ‍ Telegram | DID YOU KNOW?

Date: |

Find Channels On Telegram?

Telegram is an aspiring new messaging app that’s taking the world by storm. The app is free, fast, and claims to be one of the safest messengers around. It allows people to connect easily, without any boundaries.You can use channels on Telegram, which are similar to Facebook pages. If you’re wondering how to find channels on Telegram, you’re in the right place. Keep reading and you’ll find out how. Also, you’ll learn more about channels, creating channels yourself, and the difference between private and public Telegram channels.

Launched in 2013, Telegram allows users to broadcast messages to a following via β€œchannels”, or create public and private groups that are simple for others to access. Users can also send and receive large data files, including text and zip files, directly via the app.The platform said it has more than 500m active users, and topped 1bn downloads in August, according to data from SensorTower.Advance Java ‍ from us


Telegram Advance Java πŸ‘¨β€πŸ’»
FROM USA